// 私信
// noinspection JSUnusedLocalSymbols

import {NukeApi} from "@ginstone/nga-api/dist/src/method/NukeApi";
import {MyCache} from "@ginstone/common-utils/dist/src/utils/MyCache";
import {PmAddParam, PmKickParam, PmNewParam, PmReadParam, PmReplyParam} from "@ginstone/nga-api/dist/src/params/NukeParams";

export default {
    namespaced: true,
    state: {
        cache: new MyCache({limit: 60 * 30}),
    },
    mutations: {
        method(state, payload) {

        },
    },
    actions: {
        method: ({dispatch, commit, state, rootGetters}, payload) => {
            const client = rootGetters["Account/getClient"]();

        },
        // 查询私信列表
        pmList: ({dispatch, commit, state, rootGetters}, {page = 1, force}) => {
            const client = rootGetters["Account/getClient"]();
            const method = () => NukeApi.pmList(client, page)
            return state.cache.use({userId: client.userId, page}, method, force)
        },
        // 读私信
        pmRead: ({dispatch, commit, state, rootGetters}, {messageId, page = 1, force}) => {
            const client = rootGetters["Account/getClient"]();
            const method = () => NukeApi.pmRead(client, new PmReadParam(messageId, page))
            return state.cache.use({messageId, page}, method, force)
        },
        // 私信踢人(退出)
        pmKick: ({dispatch, commit, state, rootGetters}, {messageId, userId}) => {
            const client = rootGetters["Account/getClient"]();
            return NukeApi.pmKick(client, new PmKickParam(messageId, userId)).then(res => {
                //清空缓存
                state.cache.clear()
                return res;
            });
        },
        // 向私信会话中添加更多的参与者
        pmAdd: ({dispatch, commit, state, rootGetters}, {messageId, userIds}) => {
            const client = rootGetters["Account/getClient"]();
            return NukeApi.pmAdd(client, new PmAddParam(messageId, userIds))
        },
        // 发起新的私信
        pmNew: ({dispatch, commit, state, rootGetters}, {title, content, userIds}) => {
            const client = rootGetters["Account/getClient"]();
            return NukeApi.pmNew(client, new PmNewParam(title, content, userIds))
        },
        // 回复私信
        pmReply: ({dispatch, commit, state, rootGetters}, {messageId, title, content}) => {
            const client = rootGetters["Account/getClient"]();
            return NukeApi.pmReply(client, new PmReplyParam(messageId, title, content))
        },
        // 查询私信黑名单
        pmBlockList: ({dispatch, commit, state, rootGetters}, force) => {
            const client = rootGetters["Account/getClient"]();
            const method = () => NukeApi.pmBlockList(client)
            const param = {userId: client.userId, type: 'block'};
            return state.cache.use(param, method, force)
        },
        // 添加用户到私信黑名单
        pmBlockAdd: ({dispatch, commit, state, rootGetters}, userId) => {
            const client = rootGetters["Account/getClient"]();
            const param = {userId: client.userId, type: 'block'};
            return NukeApi.pmBlockAdd(client, userId).then(res => {
                state.cache.remove(param);
                return res;
            })
        },
        //从私信黑名单移除用户
        pmBlockDel: ({dispatch, commit, state, rootGetters}, userId) => {
            const client = rootGetters["Account/getClient"]();
            const param = {userId: client.userId, type: 'block'};
            return NukeApi.pmBlockDel(client, userId).then(res => {
                state.cache.remove(param);
                return res;
            })
        },

    },
    getters: {},
}